package core

import (
	"regexp"
	"strings"
)

func Replace(str, rule, replace string) string {
	reg := regexp.MustCompile(rule)
	return reg.ReplaceAllString(str, replace)
}

func IsStatic(fn string) bool {
	fn = strings.ToLower(fn)
	var Suffix = regexp.MustCompile(`.(css|js|jpeg|jpg|png|mp3|mp4)$`)
	res := Suffix.FindString(fn)
	if len(res) > 0 {
		return true
	} else {
		return false
	}
}


/** getTagCon
 * 获取H某个TML标签之间内容
 * return 返回找到的第一个标签之间的内容
 */
func getTagCon(str string) string {
	reg := regexp.MustCompile("# ([\\s\\S]*?)\\n[\\s]?")
	tagCon := reg.FindString(str)
	tagCon = strings.Replace(tagCon, "#", "", 1)
	// tagCon = strings.Replace(tagCon, tagEnd, "", 1)
	return tagCon
}
func getTagConAll(str string) []string {
	reg := regexp.MustCompile("\n#{2} ([\\s\\S]*?)\\n[\\s]?")
	tags := reg.FindAllString(str, -1)
	for k, _ := range tags {
		tags[k] = strings.Replace(tags[k], "##", "", 1)
	}
	return tags
}
